package Service

import (
	"web_back_go/DAO/gorm"
	"web_back_go/DAO/gorm/GormModel"
)

func GetUserAddrByUserId(addId int64, userId string) *GormModel.TzUserAddr {
	var userAddr GormModel.TzUserAddr
	db := gorm.Db

	var result error
	if addId == 0 {
		result = db.Where("user_id = ? and common_addr = ?", userId, 1).First(&userAddr).Error
	} else {
		result = db.Where("user_id = ? and addr_id = ?", userId, addId).First(&userAddr).Error
	}

	if result != nil {
		return nil
	}

	return &userAddr
}
